home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / etc / init.d / dbus < prev    next >
Text File  |  2008-10-07  |  5KB  |  182 lines

  1. #!/bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          dbus
  4. # Required-Start:    $remote_fs $syslog
  5. # Required-Stop:     $remote_fs $syslog
  6. # Default-Start:     2 3 4 5
  7. # Default-Stop:      1
  8. # Short-Description: D-Bus systemwide message bus
  9. # Description:       D-Bus is a simple interprocess messaging system, used
  10. #                    for sending messages between applications.
  11. ### END INIT INFO
  12. # -*- coding: utf-8 -*-
  13. # Debian init.d script for D-BUS
  14. # Copyright ┬⌐ 2003 Colin Walters <walters@debian.org>
  15. # Copyright ┬⌐ 2005 Sjoerd Simons <sjoerd@debian.org>
  16.  
  17. set -e
  18.  
  19. DAEMON=/bin/dbus-daemon
  20. UUIDGEN=/bin/dbus-uuidgen
  21. UUIDGEN_OPTS=--ensure
  22. NAME=dbus
  23. DAEMONUSER=messagebus
  24. PIDDIR=/var/run/dbus
  25. PIDFILE=$PIDDIR/pid
  26. DESC="system message bus"
  27. EVENTDIR=/etc/dbus-1/event.d
  28.  
  29. test -x $DAEMON || exit 0
  30.  
  31. . /lib/lsb/init-functions
  32.  
  33. # Source defaults file; edit that file to configure this script.
  34. PARAMS=""
  35. if [ -e /etc/default/dbus ]; then
  36.   . /etc/default/dbus
  37. fi
  38.  
  39. if [ -n "$ENABLED" ]; then
  40.     log_warning_msg "The ENABLED option in /etc/default/$NAME has been deprecated."
  41.     log_warning_msg "Please remove this setting from the configuration file."
  42.     log_warning_msg "To disable the service use a runlevel editor like sysv-rc-conf or bum instead."
  43. fi
  44.  
  45. create_machineid() {
  46.   # Create machine-id file
  47.   if [ -x $UUIDGEN ]; then
  48.     $UUIDGEN $UUIDGEN_OPTS
  49.   fi
  50. }
  51.  
  52. dependent_services()
  53. {
  54.   # Do nothing if we are called by init
  55.   [ ! -z $runlevel ] && return 
  56.  
  57.   # Determine current runlevel
  58.   r=$(/sbin/runlevel) || true
  59.   r=${r#*\ }
  60.  
  61.   # Do nothing if we can't determine the runlevel (e.g. inside chroots)
  62.   [ "$r" = "unknown" ] && return
  63.  
  64.   if [ "$1" = "stop" ] ; then
  65.     param="--reverse"
  66.     action="stop"
  67.   else
  68.     param=""
  69.     action="start"
  70.   fi
  71.  
  72.   # Get the list of services active in this runlevel
  73.   if [ -d /etc/rc${r}.d/ ] ; then # sysv-rc
  74.     services=$(grep -s -l "^# Required-Start:.*dbus" /etc/rc${r}.d/S??* | sort $param)
  75.   elif [ -f /etc/runlevel.conf ] ; then # file-rc
  76.     list=$(grep -s -l "^# Required-Start:.*dbus" /etc/init.d/* || true)
  77.     services=$( for i in $list ; do
  78.       grep -E "^[[:digit:]]{2}[[:space:]]+([0-9,S]+|[-])[[:space:]]+.*$r.*[[:space:]]+$i$" /etc/runlevel.conf
  79.     done  | sort $param | awk '{print $4}' )
  80.   else
  81.     services=""
  82.     log_warning_msg "Unable to determine dependent services: unknown init system"
  83.   fi
  84.  
  85.   # Start the services in the correct order
  86.   for i in $services ; do
  87.     service=$(basename $i)
  88.     service=${service#S??}
  89.     invoke-rc.d $service $action || true
  90.   done
  91.  
  92. }
  93.  
  94.  
  95. start_it_up()
  96. {
  97.   if [ ! -d $PIDDIR ]; then
  98.     mkdir -p $PIDDIR
  99.     chown $DAEMONUSER $PIDDIR
  100.     chgrp $DAEMONUSER $PIDDIR
  101.   fi
  102.  
  103.   if ! mountpoint -q /proc/ ; then
  104.     log_failure_msg "Can't start $DESC - /proc is not mounted"
  105.     return
  106.   fi
  107.  
  108.   if [ -e $PIDFILE ]; then
  109.     PIDDIR=/proc/$(cat $PIDFILE)
  110.     if [ -d ${PIDDIR} -a  "$(readlink -f ${PIDDIR}/exe)" = "${DAEMON}" ]; then 
  111.       log_success_msg "$DESC already started; not starting."
  112.       return
  113.     else
  114.       log_success_msg "Removing stale PID file $PIDFILE."
  115.       rm -f $PIDFILE
  116.     fi
  117.   fi
  118.  
  119.   create_machineid
  120.  
  121.   log_daemon_msg "Starting $DESC" "$NAME"
  122.   start-stop-daemon --start --quiet --pidfile $PIDFILE \
  123.     --user $DAEMONUSER --exec $DAEMON -- --system $PARAMS
  124.   log_end_msg $?
  125.   if [ -d $EVENTDIR ]; then
  126.       run-parts --arg=start $EVENTDIR || true
  127.   fi
  128.   dependent_services start
  129. }
  130.  
  131. shut_it_down()
  132. {
  133.   dependent_services stop
  134.   if [ -d $EVENTDIR ]; then
  135.       run-parts --reverse --arg=stop $EVENTDIR || true
  136.   fi
  137.   log_daemon_msg "Stopping $DESC" "$NAME"
  138.   start-stop-daemon --stop --retry 5 --quiet --oknodo --pidfile $PIDFILE \
  139.     --user $DAEMONUSER
  140.   # We no longer include these arguments so that start-stop-daemon
  141.   # can do its job even given that we may have been upgraded.
  142.   # We rely on the pidfile being sanely managed
  143.   # --exec $DAEMON -- --system $PARAMS
  144.   log_end_msg $?
  145.   rm -f $PIDFILE
  146. }
  147.  
  148. reload_it()
  149. {
  150.   create_machineid
  151.   log_action_begin_msg "Reloading $DESC config"
  152.   dbus-send --print-reply --system --type=method_call \
  153.             --dest=org.freedesktop.DBus \
  154.             / org.freedesktop.DBus.ReloadConfig > /dev/null
  155.   # hopefully this is enough time for dbus to reload it's config file.
  156.   log_action_end_msg $?
  157. }
  158.  
  159. case "$1" in
  160.   start)
  161.     start_it_up
  162.   ;;
  163.   stop)
  164.     shut_it_down
  165.   ;;
  166.   status)
  167.     status_of_proc -p ${PIDFILE} ${DAEMON} ${NAME} && exit 0 || exit $?
  168.   ;;
  169.   reload|force-reload)
  170.     reload_it
  171.   ;;
  172.   restart)
  173.     shut_it_down
  174.     start_it_up
  175.   ;;
  176.   *)
  177.     echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|status}" >&2
  178.     exit 2
  179.   ;;
  180. esac
  181.  
  182.